﻿@inherits LayoutComponentBase
<MApp>
  <!-- Must have the app property -->
  <MAppBar App  Color="deep-purple accent-4" Dense Dark draggable="true" @ondragstart="HandleDrop">
      <MAppBarTitle>爬书神器</MAppBarTitle>
       <MButton Icon Href="/">
            <MIcon>mdi-book-open-variant</MIcon>
        </MButton>
        
        <MButton Icon Href="/add">
            <MIcon>mdi-database-plus</MIcon>
        </MButton>
        <MButton Icon Href="/setting">
            <MIcon>mdi-tune-vertical</MIcon>
        </MButton>
        <MSpacer></MSpacer>
      @*  <Language />*@
        <MButton Icon OnClick="MinimizeForm">
            <MIcon>mdi-window-minimize</MIcon>
        </MButton>
           <MButton Icon OnClick="()=>{CloseDialog=true;}">
            <MIcon>mdi-window-close</MIcon>
        </MButton>
  </MAppBar>

  <MMain>
    <MContainer>
      @Body
    </MContainer>
    <MDialog
            @bind-Value="CloseDialog"
            Width="450">
            <ChildContent>
                <MCard>
                    <MCardTitle Class="text-h5 grey lighten-2">
                        <MIcon>mdi-alert-outline</MIcon>  正在退出应用
                    </MCardTitle>

                    <MCardText >
                        <p class="font-weight-black">你正在关闭窗口,这会导致关闭整个应用!</p>
                    </MCardText>

                    <MDivider></MDivider>

                    <MCardActions>
                        <MSpacer></MSpacer>
                         <MButton
                            Color="red"
                            Dark
                            OnClick="() => {CloseDialog = false;CloseForm();}">
                            确认
                        </MButton>
                        <MButton
                            Color="primary"
                            Dark
                            OnClick="() => {CloseDialog = false;}">
                            取消
                        </MButton>
                    </MCardActions>
                </MCard>
            </ChildContent>
        </MDialog>
  </MMain>
</MApp>
 

@code {
    [Inject] 
    private IJSRuntime JS { get; set; }



    /// <summary>
    /// 关闭窗口的模态床
    /// </summary>
    private bool CloseDialog { get; set; } = false;


    async void MinimizeForm()
    {
        await JS.InvokeVoidAsync("Photino.window.setMinimized",true);
    }

    async void HandleDrop()
    {
       await JS.InvokeVoidAsync("Photino.window.drag");
    }

    async void CloseForm()
    {
        await JS.InvokeVoidAsync("Photino.window.close");
    }

}